#!/bin/bash

#---------------------------------------------------------------------
# Script  : postlight
#---------------------------------------------------------------------
# Purpose : Script that end the full installation 
#---------------------------------------------------------------------
# History :
#
# 12/2004 LS Creation
#---------------------------------------------------------------------

echo 'PATIENT INSTALLER - START POSTFLIGHT SCRIPT'

# Echoes the script arguments
echo "The full path to the install package : $1"
echo "The full path to the install destination : $2"
echo "The mount point of the destination volume : $3"
echo "The root directory for the current system folder : $4"

target="$2Applications/KDIS Mac OS X"
if [ -e "$target"/'Patient' ] ; then
   (cd "$target" && chown root:admin 'Patient' && chmod 777 'Patient')
   echo 'The Patient application is successfully installed'
else
   echo 'Fail to install the Patient application'
   exit 1
fi


# Modify the current /etc/smb.conf to allow file sharing 
# over a network 

# Search for a previous installation
 cat /etc/smb.conf | grep -q "\[KDIS\]"

#install
if [ $? -eq 1 ]
then
# $? Exit status return 1 first installation  
# Adding Kodak file sharing configuration to /etc/smb.conf

  echo "

  #This section establishes the file sharing between Mac and Windows workstations
  #It must not be removed or modified
  [Kodak]
  path = /Users/%u/Public/Kodak
  comment = Kodak Repository

  browsable = yes
  writeable = yes

  create mask = 0666
  directory mask = 0777

  " >> /etc/smb.conf

#reboot servers
killall -HUP smbd
killall -HUP nmbd

echo 'The smb coniguration file has been successfully modified'

else
# $? Exit status return 0 if a previous installation of KDIS had been made  
echo 'The smb coniguration file has been already modified'
fi

#remove the Resources temporary folder
if [ -e "$2/Resources" ] ; then
   (rm -R "$2/Resources")
   echo 'The Resources temporary folder is successfully removed'
fi

echo 'PATIENT INSTALLER - END POSTFLIGHT SCRIPT'

exit 0
